package com.providersave.service;

import com.providersave.mapper.WarehouseMapper;
import org.springframework.stereotype.Service;
import pojo.Warehouse;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WarehouseServiceImpl implements WarehouseService{
    @Resource
    private WarehouseMapper warehouseMapper;

    /**
     * 添加仓库信息
     * @param warehouse
     * @return
     */
    @Override
    public boolean addWarehouse(Warehouse warehouse) {
        boolean flag = false;
        if(warehouseMapper.addWarehouse(warehouse) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean removeWarehouseById(Long id) {
        boolean flag = false;
        if(warehouseMapper.removeWarehouseById(id) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean modifyWarehouse(Warehouse warehouse) {
        boolean flag = false;
        if(warehouseMapper.modifyWarehouse(warehouse) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public List<Warehouse> findWarehousePagingByCondition(Warehouse warehouse, Integer pageIndex, Integer pageSize) {
        //计算分页查询开始位置
        Integer _pageIndex = (pageIndex-1)*pageSize;
        return warehouseMapper.findWarehousePagingByCondition(warehouse,_pageIndex,pageSize);
    }

    @Override
    public int findWarehouseCountByCondition(Warehouse warehouse) {
        return warehouseMapper.findWarehouseCountByCondition(warehouse);
    }

    @Override
    public List<Warehouse> findAllUsableWarehouse() {
        return warehouseMapper.findAllUsableWarehouse();
    }
}
